package com.itbaizhan.springbootdemo4.servlet;

import org.springframework.boot.SpringBootConfiguration;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/*注册web组件，方式二
* 1，编写servlet
* 2，使用配置类注册servlet*/
@SpringBootConfiguration
public class SecondServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("second servlet");
    }
}

/*编写servlet

public class SecondServlet extends HttpServlet {
  public void doGet(HttpServletRequest request, HttpServletResponse response){
    System.out.println("Second Servlet........");
   }
}
使用配置类注册servlet

@Configuration
//或 @SpringBootConfiguration
public class ServletConfig {
  //ServletRegistrationBean可以注册Servlet组件，将其放入Spring容器中即可注册Servlet
  @Bean
  public ServletRegistrationBean getServletRegistrationBean(){
    // 注册Servlet组件
    ServletRegistrationBean bean = new ServletRegistrationBean(new SecondServlet());
    // 添加Servlet组件访问路径
    bean.addUrlMappings("/second");
    return bean;
   }
}*/